#!/bin/bash

echo "=== 安装 Docker 所需依赖 ==="
apt-get update
apt-get install -y ca-certificates curl gnupg lsb-release

echo "=== 添加 Docker GPG 密钥 ==="
mkdir -p /etc/apt/keyrings
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.aliyun.com/docker-ce/linux/debian \
  $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null

echo "=== 更新软件包列表并安装 Docker 引擎 ==="
apt-get update
apt-get install -y docker-ce docker-ce-cli containerd.io

echo "=== 启动 Docker 并设置为开机自启 ==="
systemctl enable docker
systemctl start docker

echo "=== Docker 安装完成 ==="
docker --version

